<?php if ($session->read('Auth.User.is_head_user') == false && $session->read('Auth.User.can_view_other_site') == true) : // ถ้าเป็น Site user และ ดู site อื่นได้
    $user = $session->read('Auth.User'); ?>
<div style="float:right; position: relative; top: 3px;">
        <?php echo $ajax->form('CustProductSites', 'post', array('update' => 'content', 'indicator' => 'indicator','url' => array('controller' => 'cust_product_sites', 'action' => 'change_view_site')));
        echo 'View Site Inventory ' . $form->select('view_site_inventory', $this->requestAction('sites/site_list/'. $user['customer_id'] . '/allOption:true'),
                isset($user['Extend']['view_site_inventory'])? $user['Extend']['view_site_inventory']: $user['site_id'],
                array('id' => 'viewSiteInventory', 'name' => 'data[view_site_inventory]'), false);
        echo $form->submit('submit', array('class' => 'hide', 'id' =>'viewSiteInventorySubmit'));
        echo $form->end();
        ?>
    <script type="text/javascript">
        $("viewSiteInventory").observe("change", function(event) {
            $j("#viewSiteInventorySubmit").trigger("click");
        });
    </script>
</div>
<br />
<?php endif; ?>

<?php echo $this->element('displayHeader'); ?>

<div class="toolbar">
    <div id="tLeft"><?php echo $this->element('toolbar', array('buttons' => array('back'))); ?></div>
    <div id="tRight"><?php echo $this->element('neighbors', array('model' => 'CustProductSite', 'title' => 'stock_code')); ?></div>
</div>

<fieldset>
    <legend>General Information</legend>
    <table class="wide">
        <tr>
            <td width="130px"><?php echo $form->label('CustProductSite.stock_code') ;?></td>
            <td width="350px" align="left"><?php echo $this->data['CustProductSite']['stock_code'] ?></td>
            <td width="150px"><?php echo $form->label('Product.part_no', 'Vendor Part no.') ;?></td>
            <td><?php echo $this->data['CustProductSite']['dispatch_from'] == ITS_PREFIX? $this->data['Product']['part_no']: $this->data['Product']['supplier_part_no']; ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('Product.category_id') ;?></td>
            <td><?php echo isset($this->data['Product']['Category']['name'])? $this->data['Product']['Category']['name'] : '-' ?></td>
            <td><?php echo $form->label('CustProductSite.dispatch_from', 'Vendor') ;?></td>
            <td><?php echo $this->data['CustProductSite']['dispatch_from'] == ITS_PREFIX? $this->requestAction('system_preferences/get/company_name') : $this->data['Supplier']['name']; ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('Product.model') ;?></td>
            <td><?php echo $this->data['Product']['model'] ?></td>
            <td><?php echo $form->label('Product.brand_id') ;?></td>
            <td><?php echo $this->data['Product']['Brand']['name'] ?></td>
        </tr>
        <tr>
            <td class="top"><?php echo $form->label('Product.title', 'Title') ;?></td>
            <td <?php $session->read('Auth.User.hide_price') == true? 'colspan="3"': null ?>><?php echo $this->data['Product']['title'] ?></td>
            <?php if($session->read('Auth.User.hide_price') != true) : ?>
            <td><?php echo $form->label('CustProductsite.latest_price') ;?></td>
            <td colspan="3">
                <?php echo number_format($this->data['CustProductSite']['price'], 2); ?> Baht
                <?php echo $ajax->link($html->image('icon/popup.png', array('title' => 'Price History')),
                                        array('controller' => 'its_cust_product_sites', 'action' => 'popup_view_price', $this->data['CustProductSite']['id'], true),
                                        array('update' => 'content', 'position' => 'bottom', 'indicator' => 'indicator'), null, false);
                ?>
            </td>
            <?php endif; ?>
        </tr>
        <tr>
            <td class="top"><?php echo $form->label('Product.text', 'Description') ;?></td>
            <td colspan="3">
                <?php echo !empty($this->data['CustProductSite']['text'])?
                $this->data['CustProductSite']['text']:
                $this->data['Product']['text']; ?>
            </td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend>Application Information</legend>
    <table class="wide">
        <tr>
            <td width="150px"><?php echo $form->label('CusProductSite.mc', 'M/C') ;?></td>
            <td width="350px"><?php echo !empty($this->data['CustProductSite']['mc'])? $this->data['CustProductSite']['mc']: '-' ?></td>
            <td width="150px"><?php echo $form->label('CusProductSite.fluid') ;?></td>
            <td><?php echo !empty($this->data['CustProductSite']['fluid'])? $this->data['CustProductSite']['fluid']: '-' ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('CusProductSite.temp') ;?></td>
            <td><?php echo !empty($this->data['CustProductSite']['temp'])? $this->data['CustProductSite']['temp']: '-' ?> Celsius</td>
            <td><?php echo $form->label('CusProductSite.pressure') ;?></td>
            <td><?php echo !empty($this->data['CustProductSite']['pressure'])? $this->data['CustProductSite']['pressure']: '-' ?> Psi.</td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend>Moving Information</legend>
    <table>
        <tr>
            <td width="200px"><?php echo $form->label('CusProductSite.critical_part'); ?></td>
            <td width="50px" class="text-right"><?php echo ($this->data['CustProductSite']['critical_part'])? "Yes" : "No"; ?></td>
            <td width="240px">&nbsp;</td>
            <td width="200px"><?php echo $form->label('CusProductSite.current_stock'); ?></td>
            <td width="50px" class="text-right"><?php echo $this->data['CustProductSite']['current_stock'] != null? $this->data['CustProductSite']['current_stock']: '-' ?></td>
            <td>
                <?php echo $this->data['Product']['Unit']['title'] ?>
                <?php echo $ajax->link($html->image('icon/popup.png', array('alt' => 'Index information')),
                array('controller' => 'products_serials', 'action' => 'popup_cust_view', $this->data['CustProductSite']['id']),
                array('update' => 'content', 'position' => 'bottom', 'indicator' => 'indicator' ), null, false); ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form->label('CusProductSite.critical_mc', 'Critical M/C'); ?></td>
            <td class="text-right"><?php echo ($this->data['CustProductSite']['critical_mc'])? "Yes" : "No"; ?></td>
            <td>&nbsp;</td>
            <td width="200px"><?php echo $form->label('CusProductSite.reserve_qty', 'Reserved Qty.'); ?></td>
            <td width="50px" class="text-right"><?php echo $this->data['CustProductSite']['reserve_qty'] != null? $this->data['CustProductSite']['reserve_qty']: '-' ?></td>
            <td>
                <?php echo $this->data['Product']['Unit']['title'] ?>
            </td>
        </tr>
        <tr>
            <td><?php echo $form->label('CustProductSite.cycle_time'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['cycle_time'])? $this->data['CustProductSite']['cycle_time']: 'N/A' ?></td>
            <td>
                <?php if (!empty($this->data['CyclePeriod']['title']) && !empty($this->data['CustProductSite']['cycle_time']))
                    echo $this->data['CyclePeriod']['title'] ?>
            </td>
            <td><?php echo $form->label('CusProductSite.ex_stock', 'Ex-Stock before consign:') ;?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['ex_stock'])? $this->data['CustProductSite']['ex_stock']: '-' ?></td>
            <td><?php echo $this->data['Product']['Unit']['title'] ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('CusProductSite.shortest_life_cycle'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['shortest_life_cycle'])? $this->data['CustProductSite']['shortest_life_cycle']: 'N/A' ?></td>
            <td>
                <?php if (!empty($this->data['ShortestPeriod']['title']) && !empty($this->data['CustProductSite']['shortest_life_cycle']))
                    echo $this->data['ShortestPeriod']['title'] ?>
            </td>
            <td><?php echo $form->label('CusProductSite.min_stock'); ?></td>
            <td class="text-right"><?php echo !($this->data['CustProductSite']['min_stock'] === null)? $this->data['CustProductSite']['min_stock']: '-' ?></td>
            <td><?php echo $this->data['Product']['Unit']['title'] ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('CusProductSite.maintenance_plan', 'Maintenance plan(every)'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['maintenance_plan'])? $this->data['CustProductSite']['maintenance_plan']: '-' ?></td>
            <td>
                <?php if (!empty($this->data['MaintenancePeriod']['title']) && !empty($this->data['CustProductSite']['maintenance_plan']))
                    echo $this->data['MaintenancePeriod']['title'] ?>
            </td>
            <td><?php echo $form->label('CusProductSite.max_stock'); ?></td>
            <td class="text-right"><?php echo !($this->data['CustProductSite']['max_stock'] === null)? $this->data['CustProductSite']['max_stock']: '-' ?></td>
            <td><?php echo $this->data['Product']['Unit']['title'] ?></td>
        </tr>
        <tr>
            <td><?php echo $form->label('CusProductSite.complete_consignment_date', 'Complete Consignment on'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['complete_consignment_date'])? $this->data['CustProductSite']['complete_consignment_date']: '-' ?></td>
            <td>&nbsp;</td>
            <td><?php echo $form->label('CusProductSite.last_stock_in_date', 'Last Stock in Date'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['last_stock_in_date'])? $this->data['CustProductSite']['last_stock_in_date']: '-' ?></td>
        </tr>
        <tr>
            <td colspan="3">&nbsp;</td>
            <td><?php echo $form->label('CusProductSite.last_stock_out_date', 'Last Stock out Date'); ?></td>
            <td class="text-right"><?php echo !empty($this->data['CustProductSite']['last_stock_out_date'])? $this->data['CustProductSite']['last_stock_out_date']: '-' ?></td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend>Barcode</legend>
    <table class="wide">
        <tr>
            <td width="150px">&nbsp;</td>
            <td>
                <?php if (isset($this->data['Product']['has_barcode']) && $this->data['Product']['has_barcode']) : ?>
                <img src="<?php echo "{$this->base}/products/barcode_image/{$this->data['Product']['id']}" ?>" alt="barcode image" />
                <?php else : ?>&nbsp;
                <?php endif; ?>
            </td>
        </tr>
    </table>
</fieldset>
<fieldset>
    <legend>Picture</legend>
    <table class="wide">
        <tr>
            <td class="center">
                <?php if (isset($this->data['Product']['has_picture_1']) && $this->data['Product']['has_picture_1']) : ?>
                <img src="<?php echo "{$this->base}/products/product_image/{$this->data['Product']['id']}/1" ?>" alt="Picture image 1" /><br />
                <?php else : ?>&nbsp;
                <?php endif; ?>
            </td>
            <td class="center">
                <?php if (isset($this->data['Product']['has_picture_2']) && $this->data['Product']['has_picture_2']) : ?>
                <img src="<?php echo "{$this->base}/products/product_image/{$this->data['Product']['id']}/2" ?>" alt="Picture image 2" /><br />
                <?php else : ?>&nbsp;
                <?php endif; ?>
            </td>
        </tr>
    </table>
</fieldset>

<fieldset>
    <legend>Available Locations</legend>
    <div id="divCPSLocations">
            <?php echo $this->requestAction('its_cust_product_sites/display_locations/' . $this->data['CustProductSite']['id'], array('return')); ?>
    </div>
</fieldset>